package wyp.library.tools;

import java.io.File;
import java.io.RandomAccessFile;

import android.os.Environment;

public class WypSdCardTool {

	public static boolean write(String __subPath, String __context) {
		boolean __retrun = false;
		try {
			if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
				File sdCardDir = Environment.getExternalStorageDirectory();// 获取SD卡的目录
				File targetFile = new File(sdCardDir.getCanonicalPath() + File.separator +  __subPath);
				if(targetFile.getParentFile().exists() == false){
					targetFile.getParentFile().mkdirs();
				}
				if(targetFile.exists() == true && targetFile.isFile() == true){
					targetFile.delete();
				}
				// 以指定文件创建RandomAccessFile对象
				RandomAccessFile __raf = new RandomAccessFile(targetFile, "rw");
				// 将文件记录指针移动到最后
				__raf.seek(targetFile.length());
				// 输出文件内容
				__raf.write(__context.getBytes());
				__raf.close();
			}
			__retrun = true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return __retrun;
	}
}
